<?php
/**
 * Created by IntelliJ IDEA.
 * User: XD
 * Date: 2017/8/24
 * Time: 10:13
 */
namespace app\mysql\app\builder;
use app\log\UseLog;

class MysqlBuilder extends MysqlBuilderabs
{
    protected $selectconfig="local";
    protected $config;
    protected $options;
    function __construct($selectconfig,$config=null)
    {
        parent::__construct();
        $this->config= $selectconfig;
        if (is_null($config)){
            $this->config = __DIR__."/../config/MysqlConfig.php";
        }
        $this->setoptions();

    }

    function setoptions(){
        if (file_exists($this->config)) {
            include ($this->config);
        }else{
            throw new \Exception("Mysql Config file does not exist!");
        }
        
        if (empty($mysqlconfigparameter) || !is_array($mysqlconfigparameter)){
            throw new \Exception("No mysqlconfigparameter defined at MysqlConfig file!");
        }
       
        if(array_key_exists($this->selectconfig,$mysqlconfigparameter)){
            $this->options = $mysqlconfigparameter[$this->selectconfig];
        }else{
            \app\log\UseLog::addInfoAtLog('mysql 配置文件指定的二维数组中没有相应的一维数组配置',__FILE__,__LINE__);
        }
    }

    function BuildServerName()
    {
        // TODO: Implement BuildServerName() method.
        $this->_mysqlModel->setServername($this->options["servername"]);
    }

    function BuildUserName()
    {
        // TODO: Implement BuildUserName() method.
        $this->_mysqlModel->setUsername($this->options["username"]);
    }

    function BuildPassword()
    {
        // TODO: Implement BuildPassword() method.
        $this->_mysqlModel->setPassword($this->options["password"]);
    }

    function BuildDB()
    {
        // TODO: Implement BuildDB() method.
        $this->_mysqlModel->setDb($this->options["dbname"]);
    }

    function BuildPort()
    {
        // TODO: Implement BuildDB() method.
        $this->_mysqlModel->setPort($this->options["port"]);
    }

    function GetMysql()
    {
        // TODO: Implement GetMysql() method.
        return $this->_mysqlModel;
    }
}
